/*
 * Copyright (c) 2017 <l_iupeiyu@qq.com> All rights reserved.
 */

package com.uyayo.oms.shiro;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * author geekcattle
 * date 2017/3/21 0021 下午 16:33
 */
public class ManagerAuthenticationFilter extends FormAuthenticationFilter {

	@Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
    	try {
	    	Subject subject = getSubject(request, response);
	        if(subject.getPrincipal() != null){
	        	return super.isAccessAllowed(request, response, mappedValue);
	        }else{
	            return super.isAccessAllowed(request, response, mappedValue);
	        }
    	} catch (Exception e) {
			return false;
		}
    }

    @Override
    public void setLoginUrl(String loginUrl) {
        super.setLoginUrl("/oms/login");
    }

    @Override
    public void setSuccessUrl(String successUrl) {
        super.setSuccessUrl("/oms/index");
    }

}
